<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">request</button>
    <script>
        let btn = document.querySelector('#btn');
        
        //监听异步操作
        btn.addEventListener('click',async() => {
            try{
                let msg = await fetch(`http://${location.host}/index`).then(res=>res.text());
                console.log('msg=====>',msg);
            }catch(err){
                console.log('err=====>',err);
            }
        })
    </script>
    
</body>
</html>